package cn.pink.gamesrv.msg;

import cn.pink.common.support.MsgRoute;
import cn.pink.core.support.Log;
import cn.pink.core.support.Param;
import cn.pink.core.support.observer.MsgSubject;
import cn.pink.gamesrv.account.AccountMsgHandler;
import cn.pink.gamesrv.human.HumanObject;
import com.google.protobuf.GeneratedMessageV3;

/**
 * @Author: pink
 * @Date: 2022/6/30 18:55
 */
public class HumanMsgRoute extends MsgRoute {
    @Override
    public void route(GeneratedMessageV3 msg, Param param) {
        HumanObject humanObj = param.get("humanObj");
        int msgId = param.getInt("msgId");

        // 用户还没有登陆完毕，却受到了客户端消息，丢弃
        if (humanObj.isLogging() /*|| humanObj.isSwitching()*/) {
            Log.game.info("Drop message, human is logining, msg={}", msg.getClass().getSimpleName());
            return;
        }

        if (AccountMsgHandler.protos.contains(msgId)){
            Log.game.error("已经登陆了，还发登陆相关协议 客户端尽快找到错误 {} {}", msgId, msg.getClass().getSimpleName());
        }

        MsgParamHuman mp = new MsgParamHuman(msg);
        mp.setHumanObj(humanObj);

        MsgSubject.fire(msgId, mp);
    }
}
